package com.zhida.smartcontrol.pagectrl.delprojectdialog;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.zhida.smartcontrol.R;
import com.zhida.smartcontrol.mvp.MVPBaseDialogFragment;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * author: tanjianpei
 * date: 2019/12/16 016 16:51
 * description: 删除项目确认
 */
public class DelProjectDialogFragment extends MVPBaseDialogFragment<DelProjectDialogContract.View, DelProjectDialogPresenter> implements DelProjectDialogContract.View {
    @BindView(R.id.tv_msg)
    TextView mTvMsg;

    private IDelResultListener mMyListener;

    public static DelProjectDialogFragment newInstance(String id) {
        Bundle args = new Bundle();
        args.putString("id", id);
        DelProjectDialogFragment fragment = new DelProjectDialogFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected Object getLayout() {
        return R.layout.dialog_del_device;
    }

    @Override
    protected void initDatas(Bundle savedInstanceState) {
        mTvMsg.setText("确定要删除项目吗？");
    }

    public void setIDelResultListener(IDelResultListener listener){
        mMyListener = listener;
    }

    @OnClick({R.id.btn_confirm, R.id.btn_cancel})
    public void click(View v) {
        switch (v.getId()) {
            case R.id.btn_confirm:
                String id = getArguments().getString("id");
                mPresenter.deleteProject(id);
                break;
            case R.id.btn_cancel:
                dismiss();
                break;
        }
    }

    @Override
    public void deleteResult(boolean isOk, String msg) {
        if (null != mMyListener) {
            mMyListener.delResult(isOk, msg);
        }
        dismiss();
    }

    public interface IDelResultListener {
        void delResult(boolean isOk, String msg);
    }
}
